<template>
	<a-modal :confirm-loading="handing" width="540px" v-model:open="showForm" @ok="submit">
		<a-form ref="form" :model="formData" :rules="rules" :labelCol="{ span: 5 }" :wrapper-col="{ span: 16, offset: 1 }">
			<a-form-item name="serial" label="序号">
				<a-input-number v-model:value="formData.serial" :min="1" step="1" maxlength="4" />
			</a-form-item>
			<a-form-item name="title" label="话题标题">
				<a-input v-model:value="formData.title" />
			</a-form-item>
			<a-form-item name="status" label="状态">
				<a-switch v-model:checked="formData.status" checked-children="开启" :checked-value="2" un-checked-children="关闭" :un-checked-value="1" />
			</a-form-item>
			<a-form-item name="is_try" label="试学">
				<a-switch v-model:checked="formData.is_try" checked-children="是" :checked-value="2" un-checked-children="否" :un-checked-value="1" />
			</a-form-item>
		</a-form>
	</a-modal>
</template>
<script lang="ts">
import {page, form} from "@/mixins"

export default {
	mixins: [page, form],
	data() {
		return {
			showForm: false as boolean,
			formPath: 'activity-enroll',
			formData: {
				id: undefined,
				title: '' as string,
				activity_id: 0 as number,
				serial: 1,
				status: 2 as number,
				is_try: 1 as number
			},
			rules: {
			  title: [{ required: true, trigger: 'change', message: '话题标题不能为空' }],
				serial: [{ required: true, trigger: 'change', message: '请输入排序序号' }],
			}
		}
	},
	methods: {
		add() {
			Object.assign(this.formData, {
				id: undefined,
				title: '',
				status: 2,
				serial: 1,
				is_try: 1,
				content: ''
			});
			this.showForm = true;
		},
		edit(record : object) {
			Object.assign(this.formData, record);
			this.showForm = true
		},
		afterSubmit(data: object){
			this.$emit('change', data);
			this.showForm = false
		}
	}
}
</script>